package com.njtoyo.taxi.admin.rest.presenter.open.taxi;

import cn.hutool.core.util.StrUtil;
import cn.zhxu.bs.bean.BeanAware;
import cn.zhxu.bs.bean.DbField;
import cn.zhxu.bs.bean.DbIgnore;
import cn.zhxu.bs.bean.SearchBean;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.experimental.Accessors;

@SearchBean(
        tables = "driver a left join driver_extra_information b on a.id = b.driver_id"
)
@Data
@Accessors(chain = true)
public class TaxiDeviceVersionPresenter implements BeanAware {

    /**
     * 司机ID
     */
    @DbField("a.id")
    private Long driverId;

    /**
     * 是否在线
     */
    @DbField("a.in_service")
    private Boolean inService;

    /**
     * taxiId
     */
    @DbField("a.taxi_id")
    private Long taxiId;

    /**
     * 设备信息
     */
    @DbField("b.device_auto_info")
    @JsonIgnore
    private String deviceAutoInfo;

    /**
     * 设备版本
     */
    @DbIgnore
    private String deviceVersion;

    @Override
    public void afterAssembly() {
        if (StrUtil.isNotEmpty(deviceAutoInfo)) {
            JSONObject jsonObject = JSON.parseObject(deviceAutoInfo);
            deviceVersion = jsonObject.getString("v");
        }
    }
}
